#pragma once

#include <QAxObject>

class InstanceManager
{
public:
	InstanceManager();
	~InstanceManager();

	bool Init();
	void Release();

	bool openExcel(const QString& excelName);
	bool saveExcel(const QString& path = QString());
	bool closeExcel();

	bool getSheetNames(QStringList& sheetNameList);
	bool createSheet(const QString& sheetName);
	bool destroySheet(const QString& sheetName);

	bool insertInstance(const QString& sheetName, int index);
	bool deleteInstance(const QString& sheetName, int index);

	bool moveUpInstance(const QString& sheetName, int index);
	bool moveDownInstance(const QString& sheetName, int index);

	int getInstanceCount(const QString& sheetName);

	bool setFunctionName(const QString& sheetName, int index, const QString& functionName);
	bool getFunctionName(const QString& sheetName, int index, QString& functionName);

	bool setFrontCondition(const QString& sheetName, int index, const QString& frontCondition);
	bool getFrontCondition(const QString& sheetName, int index, QString& frontCondition);

	bool setDescription(const QString& sheetName, int index, const QString& description);
	bool getDescription(const QString& sheetName, int index, QString& description);
	
	bool setRearCondition(const QString& sheetName, int index, const QString& rearCondition);
	bool getRearCondition(const QString& sheetName, int index, QString& rearCondition);

	bool setExpectedRetValue(const QString& sheetName, int index, const QString& expectedRetValue);
	bool getExpectedRetValue(const QString& sheetName, int index, QString& expectedRetValue);

	bool setParamInputValue(const QString& sheetName, int index, int paramIndex, const QString& inputValue);
	bool getParamInputValue(const QString& sheetName, int index, int paramIndex, QString& inputValue);

	bool setParamExpectedValue(const QString& sheetName, int index, int paramIndex, const QString& expectedValue);
	bool getParamExpectedValue(const QString& sheetName, int index, int paramIndex, QString& expectedValue);

private:
	bool findWorkSheet(const QString& name, QAxObject** pWorksheet);
	int getValidSheetCount();
	int getRowCount(QAxObject* worksheet);

	QAxObject m_excelObject;
	QAxObject* m_workbooks;
	QAxObject* m_workbook;
	QString m_fileName;
	QMap<QString, TInstanceList> m_sheetContentMap;
	bool m_isOpen;
};
